package com.welsmann.app.start.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import com.welsmann.app.start.dao.BaseDAO;
import com.welsmann.app.start.dao.INewsTitleDAO;
import com.welsmann.app.start.entity.NewsTitle;

@Component("NewsTitleDAO")
public class NewsTitleDAO extends BaseDAO implements INewsTitleDAO {
	
	private HibernateTemplate _ht = null;

	@Override
	public List<NewsTitle> getTop() {
		_ht = new HibernateTemplate(super.sessionFactory);
		//TODO 需要把limit参数设置成常量
		return _ht.find("from NewsTitle nt order by publish desc limit 40");
	}

	@Override
	public List<NewsTitle> getTitleListByTypeId(String typeId) {
		_ht = new HibernateTemplate(super.sessionFactory);
		return _ht.find("from NewsTitle nt where type= ? order by publish desc limit 40", typeId);
	}
	
	@Override
	public NewsTitle find(String id) {
		_ht = new HibernateTemplate(super.sessionFactory);
		List<NewsTitle> lstNt = _ht.find("from NewsTitle nt where nt.id = ?", id);
		return lstNt == null || lstNt.isEmpty() ? null : lstNt.get(0);
	}

}
